<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core">


<h:head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
	<title>Vendas</title>
</h:head>

<body class="page">
	<h:form id="form">

		<h:panelGrid  columns="3" rowClasses="title" border="1">

			<h:panelGroup>
				<h:commandLink action="#{vendaBean.salvar}" value="Novo Contato" />
			</h:panelGroup>

			<h:panelGroup>			  
			</h:panelGroup>

			<h:panelGroup>
				<h:outputText value="Perquisar por nome: " />
				<h:inputText value="#{vendaBean.venda.cliente.nome}" />
				<h:commandButton value="Ok" action="#{vendaBean.buscarPorNome}" />
			</h:panelGroup>

		</h:panelGrid>

		<h:dataTable id="items" value="#{vendaBean.vendas}" var="venda"
			border="1" styleClass="data-table"
			rendered="#{vendaBean.vendas.size() > 0}">


			<h:column headerClass="column-header-item">

				<f:facet name="header">
					<h:outputText value="*" />
				</f:facet>

				<h:commandButton value="Editar"
					action="#{vendaBean.atualizar(venda)}" />

				<f:param name="id" value="#{venda.id}" />

			</h:column>


			<h:column headerClass="column-header-item">

				<f:facet name="header">
					<h:outputText value="x" />
				</f:facet>

				<h:commandButton value="Excluir"
					action="#{vendaBean.excluir(venda)}" />

				<f:param name="id" value="#{venda.id}" />

			</h:column>


			<h:column headerClass="column-header-item">

				<f:facet name="header">
					<h:outputText value="Data" />
				</f:facet>

				<h:outputText value="#{venda.venda.data}">
					<f:convertDateTime pattern="dd/MM/yyyy" />
				</h:outputText>

			</h:column>


			<h:column headerClass="column-header-item">

				<f:facet name="header">
					<h:outputText value="Id da venda" />
				</f:facet>

				<h:outputText value="#{venda.venda.id}" />

			</h:column>


			<h:column headerClass="column-header-item">

				<f:facet name="header">
					<h:outputText value="Nome do Cliente" />
				</f:facet>

				<h:outputText value="#{venda.cliente.nome}" />

			</h:column>

			<h:column headerClass="column-header-item">

				<f:facet name="header">
					<h:outputText value="Nome do Produto" />
				</f:facet>

				<h:outputText value="#{venda.produto.nome}" />

			</h:column>


			<h:panelGroup rendered="#{vendaBean.vendas.size() == 0}">
				<tr>

					<td align="center">Não existe vendas cadastrados</td>

				</tr>

			</h:panelGroup>
		</h:dataTable>
	</h:form>
</body>
</html>